<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no" />
    <title>ajax-post</title>
    <link rel="shortcut icon" href="../img/logo.png" type="image/x-icon" />
</head>

<body>
    <div id="app"></div>
</body>
<script>
    //1、创建对象
    let xhr = {}
    if (XMLHttpRequest) {
        xhr = new XMLHttpRequest()
    } else {
        xhr = new ActiveXObject("Microsoft.XMLHTTP")
    }
    //2、打开链接
    xhr.open("POST", 'http://192.168.102.4:3000/users/test', true)

    //3、设置请求头
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    //4、发送数据
    xhr.send("username=tom&password=123")

    //5、监听状态变化
    // xhr.onload = function() {
    //   console.log(xhr.response)
    // }
    xhr.onreadystatechange = function (e) {
        if (xhr.readyState === 4 && xhr.status === 200) {
            app.innerHTML = xhr.response
        }
    }
</script>

</html>